package rmi

import java.rmi.{Naming, RemoteException}
import java.rmi.server.UnicastRemoteObject

class MyRemoteImp extends UnicastRemoteObject with MyRemote {
  @throws(classOf[RemoteException])
  override def sayHello(): String = {
    "hello, World"
  }
}

object MyRemoteImp {
  def main(args: Array[String]): Unit = {
    val service: MyRemote = new MyRemoteImp()
    //准备把服务绑定到9999端口
    //方法1
    //    LocateRegistry.createRegistry(10000)
    //    Naming.rebind("RemoteHello", service)
    Naming.rebind("rmi://127.0.0.1:9999/RemoteHello", service)
    println("远程服务开启,在127.0.0.1 :9999 端口监听,服务名为 RemoteHello")
  }
}
